<template>
  <div class="app-container customer-div">
    <div style="margin-top: 40px">

      <!--搜索-->
      <el-form :inline="true" :model="listQuery" size="mini" label-width="120px">
        <el-form-item label="发货单号：">
          <el-input v-model="listQuery.deliverSn"></el-input>
        </el-form-item>
<!--        <el-form-item label="订单时间：">-->
<!--          <el-date-picker-->
<!--                  :default-time="['00:00:00', '23:59:59']"-->
<!--                  v-model="listQuery.createDate"-->
<!--                  type="daterange"-->
<!--                  format="yyyy 年 MM 月 dd 日"-->
<!--                  value-format="yyyy-MM-dd HH:mm:ss"-->
<!--                  range-separator="至"-->
<!--                  start-placeholder="开始日期"-->
<!--                  end-placeholder="结束日期">-->
<!--          </el-date-picker>-->
<!--        </el-form-item>-->
        <el-form-item label="发货日期：">
          <el-date-picker
                  :default-time="['00:00:00', '23:59:59']"
                  v-model="listQuery.deliverDate"
                  type="daterange"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="客户名称：">
          <el-autocomplete
                  clearable
                  class="inline-input"
                  value-key="customerName"
                  :fetch-suggestions="querySearch"
                  v-model="listQuery.customerName"
                  placeholder="请输入内容"
                  @select="handleSelectCustomerName"
                  :trigger-on-focus="false"
                  style="width: 270px;"
          ></el-autocomplete>
        </el-form-item>
        <el-form-item label="业务员：">
          <el-select v-model="listQuery.userId" filterable placeholder="请选择" multiple>
            <el-option
                    v-for="item in userOptionList"
                    :key="item.userId"
                    :label="item.userName"
                    :value="item.userId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="采购员：">
          <el-select v-model="listQuery.purchaseUserId" filterable placeholder="请选择" clearable>
            <el-option
                    :key="-1"
                    label="无采购员"
                    :value="-1">
            </el-option>
            <el-option
                    v-for="item in userOptionList"
                    :key="item.userId"
                    :label="item.userName"
                    :value="item.userId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="牌号：" >
          <!-- <el-select v-model="listQuery.kingGoodsIds" filterable placeholder="请选择" clearable multiple="">
            <el-option
                    v-for="item in goodsList"
                    :key="item.kingId"
                    :label="item.goodsSn"
                    :value="item.kingId">
            </el-option>
          </el-select> -->
         <el-input v-model="listQuery.goodsSn" clearable></el-input>
        </el-form-item>
        <el-form-item label="送货类型：" >
          <el-select v-model="listQuery.isYunlianDeliver" filterable placeholder="请选择" clearable>
            <el-option
                    :key="1"
                    label="运联发货"
                    :value="1">
            </el-option>
            <el-option
                    :key="0"
                    label="采购发货"
                    :value="0">
            </el-option>
            <el-option
                    :key="2"
                    label="自提"
                    :value="2">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="订单号：">
          <el-input v-model="listQuery.orderSn"></el-input>
        </el-form-item>
        <el-form-item label="费用类型：" >
          <el-select v-model="listQuery.freightType" filterable placeholder="请选择" clearable>
            <el-option key="sale" label="销售承担" value="sale"></el-option>
            <el-option key="purchase" label="采购承担" value="purchase"></el-option>
            <el-option key="logistics" label="运联承担" value="logistics"></el-option>
            <el-option key="customer" label="客户承担" value="customer"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="合同公司：" >
          <el-input v-model="listQuery.fromCompany"></el-input>
        </el-form-item>
        <el-form-item label="采购评级：" >
          <el-select v-model.number="listQuery.customerLabel" class="input-width" style="width:195px" placeholder="请选择" clearable >
            <el-option value="A类" label="A类" key="A类"></el-option>
            <el-option value="B类" label="B类" key="B类"></el-option>
            <el-option value="C类" label="C类" key="C类"></el-option>
            <el-option value="D类" label="D类" key="D类"></el-option>
            <el-option value="E类" label="E类" key="E类"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="推荐类型：" >
          <el-select v-model="listQuery.introducerType" class="input-width" style="width:195px" placeholder="请选择" clearable >
            <el-option :key="1" label="外部人员" :value="1"></el-option>
            <el-option :key="2" label="内部人员" :value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="推荐人：" >
          <el-input v-model="listQuery.introducerName"></el-input>
        </el-form-item>
        <el-form-item label="采购源单号：">
          <el-input v-model="listQuery.purchaseEntrySn"></el-input>
        </el-form-item>
        <el-form-item label="运费收款人：">
          <el-input v-model="listQuery.payeeUserName"></el-input>
        </el-form-item>
        <el-form-item label="是否有票据：" >
          <el-select v-model="listQuery.isHasBill" filterable placeholder="请选择" clearable>
            <el-option :key="1" label="是" :value="1"></el-option>
            <el-option :key="0" label="否" :value="0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="实际发货仓库：" >
          <el-select v-model="listQuery.shipWarehouse" filterable placeholder="请选择" clearable multiple>
              <el-option v-for="item in shipWarehouseList" :value="item" :label="item" :key="item"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="订单标签：" >
          <el-select v-model="listQuery.isMoresuOnlineOrder" class="input-width" style="width:150px" placeholder="请选择" clearable>
            <el-option :key="0" label="销售订单" :value="0"></el-option>
            <el-option :key="1" label="推广订单" :value="1"></el-option>
          </el-select>
        </el-form-item>
         <el-form-item label="是否为外贸订单：">
          <el-select v-model="listQuery.isChina" filterable placeholder="请选择" clearable style="width:100px">
            <el-option :key="2" label="是" :value="2"></el-option>
            <el-option :key="1" label="否" :value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="运费维护时间：">
          <el-date-picker
            :default-time="['00:00:00', '23:59:59']"
            v-model="listQuery.freightTime"
            type="daterange"
            format="yyyy 年 MM 月 dd 日"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="是否过滤订单：">
          <el-select style="width:100px" v-model="listQuery.isFilterOrder" clearable>
            <el-option label="否" :value="0"></el-option>
            <el-option label="是" :value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="产品名称：">
           <el-input v-model="listQuery.goodsName" clearable></el-input>
        </el-form-item>
        <el-form-item label="订单支付状态：">
          <el-select style="width:100px" v-model="listQuery.payState" clearable multiple>
            <el-option label="未支付" :value="0"></el-option>
            <el-option label="未结清" :value="1"></el-option>
            <el-option label="已结清" :value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="">
           <el-checkbox v-model="listQuery.isNewCustomer" :true-label="1" :false-label="0">新客户</el-checkbox>
        </el-form-item>
        <el-form-item label="供应商：">
          <el-select
            clearable
            v-model="listQuery.supplierId"
            filterable
            reserve-keyword
            placeholder="请输入关键词"
            style="width: 270px;">
            <el-option
              v-for="item in options2"
              :key="item.supplierId"
              :label="item.supplierName"
              :value="item.supplierId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否长协：">
          <el-select v-model="listQuery.isAgreement"  placeholder="请选择" clearable>
            <el-option label="是" :value="1"></el-option>
            <el-option label="否" :value="0"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="牌号系数：">
          <el-select v-model="listQuery.profitRate" filterable placeholder="请选择" multiple>
            <el-option
              v-for="item in profitRateList"
              :key="item"
              :label="item"
              :value="item">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="订单是否关闭：">
          <el-select v-model="listQuery.isOrderClose" placeholder="请选择" clearable>
            <el-option label="是" value="1"></el-option>
            <el-option label="否" value="0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="订单分类：" >
          <el-select v-model="listQuery.orderCustomerType" filterable clearable>
            <el-option
              v-for="(item,index) in orderCustomerTypeList"
              :key="index"
              :label="item.cddValue"
              :value="item.cddValue">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button
                  @click="handleSearchList()"
                  type="primary">
            查询
          </el-button>
          <el-button
                  :loading="downloadLoading"
                  v-if="deliverDetailsReportExport"
                  @click="downloadExcel"
                  type="primary">
            导出
          </el-button>
        </el-form-item>
      </el-form>
    </div>

    <!--数据列表-->
    <div style="font-size:14px;line-height: 30px;padding:10px 0 ">
      发货数量：<span style="font-weight: bold;padding-right:10px">{{sendAllNum }}</span>
      金蝶毛利：<span style="font-weight: bold;padding-right:10px">{{allProfit }}</span>
      运联含税运费合计:<span style="font-weight: bold;padding-right:10px">{{actualFreight }}</span>
      销售现金价毛利:<span style="font-weight: bold;padding-right:10px">{{saleProfit }}</span>
      采购现金价毛利:<span style="font-weight: bold;padding-right:10px">{{purchaseProfit }}</span>
    </div>
    <div class="table-container" style="margin-top:0">
      <el-table
              v-loading="listLoading"
              :data="tableData"
              border
              style="width: 100%;">
        <el-table-column
                label="合同类型"
                width="100"
                align="center">
          <template slot-scope="scope">
            {{scope.row.orderType}}
          </template>
        </el-table-column>
        <el-table-column  label="订单日期" width="100" align="center" prop="orderDate">
        </el-table-column>
        <el-table-column  label="订单号" width="180" align="center">
          <template slot-scope="scope">
            <el-link @click="toOrderDetail(scope.row.orderId)" type="primary" style="font-size:12px">
              {{scope.row.orderSn}}
            </el-link>
            <span v-if="scope.row.isEntrust == 1" style="display: inline-block;width:22px;line-height: 18px;background: green;color:#fff;font-size:12px;border-radius: 4px;text-align: center">投</span>
          </template>
        </el-table-column>
        <el-table-column
          label="订单分类"
          align="center"
          width="150">
          <template slot-scope="scope">
            {{scope.row.orderCustomerType}}
          </template>
        </el-table-column>
        <el-table-column  label="订单支付状态" width="100" align="center">
          <template slot-scope="scope">
            {{scope.row.payStateStr}}
          </template>
        </el-table-column>
        <el-table-column  label="单据类型" width="100" align="center" prop="deliverType">
        </el-table-column>
        <el-table-column  label="合同公司" width="100" align="center" prop="fromCompany">
        </el-table-column>
        <el-table-column  label="采购评级" width="100" align="center" prop="customerLabel">
        </el-table-column>
        <el-table-column  label="发货日期" width="100" align="center" prop="shipTime">
        </el-table-column>
        <el-table-column  label="发货单号" width="140" align="center">
          <template slot-scope="scope">
            <el-link @click="toDeliverDetail(scope.row.deliverId)" type="primary" style="font-size:12px">
              {{scope.row.deliverSn}}
            </el-link>
          </template>
        </el-table-column>
        <el-table-column
                label="发货类型"
                align="center"
                width="100">
          <template slot-scope="scope">
            {{scope.row.sendType}}
          </template>
        </el-table-column>
        <el-table-column  label="业务员" width="100" align="center">
          <template slot-scope="scope">
            {{scope.row.userRealName}}
          </template>
        </el-table-column>
        <el-table-column  label="军团" width="100" align="center">
          <template slot-scope="scope">
            {{scope.row.departmentName}}
          </template>
        </el-table-column>
        <el-table-column
                label="客户名称"
                width="300">
          <template slot-scope="scope">
            {{scope.row.customerName}}
          </template>
        </el-table-column>
        <el-table-column
            label="订单种类"
            width="100"
            align="center">
            <template slot-scope="scope">
              {{scope.row.isChina}}
            </template>
          </el-table-column>
        <el-table-column
                label="产品名称"
                align="center"
                width="150">
          <template slot-scope="scope">
            {{scope.row.goodsName}}
          </template>
        </el-table-column>
        <el-table-column
                label="牌号"
                align="center"
                width="150">
          <template slot-scope="scope">
            {{scope.row.goodsSn}}
          </template>
        </el-table-column>
        <el-table-column
                label="厂家"
                width="200"
                align="center">
          <template slot-scope="scope">
            {{scope.row.brandName }}
          </template>
        </el-table-column>
        <el-table-column
                label="供应商"
                width="200"
                align="center">
          <template slot-scope="scope">
            {{scope.row.supplierName }}
          </template>
        </el-table-column>
        <el-table-column
                prop="goodsNum"
                label="合同数量"
                width="100"
                align="center">
        </el-table-column>
        <el-table-column
                label-class-name="bgth"
                label="合同单价"
                width="100"
                align="center">
          <template slot-scope="scope">
            {{scope.row.goodsPrice}}
          </template>
        </el-table-column>
        <el-table-column
                label-class-name="bgth"
                label="杂费(装卸费)"
                width="80"
                align="center">
          <template slot-scope="scope">
            {{scope.row.consultation}}
          </template>
        </el-table-column>
        <el-table-column
                label="合同行备注"
                width="400">
          <template slot-scope="scope">
            {{scope.row.remark}}
          </template>
        </el-table-column>
        <el-table-column
                label-class-name="bgth"
                label="本次发货数量"
                width="120"
                align="center">
          <template slot-scope="scope">
            {{scope.row.shipNum}}
          </template>
        </el-table-column>
        <el-table-column
                label="发货批号"
                width="120"
                align="center">
          <template slot-scope="scope">
            {{scope.row.batchNo}}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="销售合同结算方式"
          width="150">
          <template slot-scope="scope">
            {{scope.row.salePayMethod}}
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          label="成本价结算方式"
          width="150">
          <template slot-scope="scope">
            {{scope.row.goodsPayMethod}}
          </template>
        </el-table-column>
        <el-table-column
                label="运联含税运费"
                width="100"
                align="center">
          <template slot-scope="scope">
            {{scope.row.ogFreight}}
          </template>
        </el-table-column>
        <el-table-column
                label="实际运费"
                width="80"
                align="center">
          <template slot-scope="scope">
            {{scope.row.actualFreight}}
          </template>
        </el-table-column>
        <el-table-column
          label="运费维护时间"
          width="150"
          align="center">
          <template slot-scope="scope">
            {{scope.row.freightTime}}
          </template>
        </el-table-column>
        <el-table-column
                label="运费差异"
                width="100"
                align="center">
          <template slot-scope="scope">
            {{scope.row.diffFreight}}
          </template>
        </el-table-column>
        <el-table-column
                label="运费差异承担"
                width="100"
                align="center">
          <template slot-scope="scope">
            {{scope.row.diffFreightType}}
          </template>
        </el-table-column>
        <el-table-column
                label="运费差异原因"
                width="200">
          <template slot-scope="scope">
            {{scope.row.diffFreightReason}}
          </template>
        </el-table-column>
        <el-table-column
                label="司机运费"
                width="80"
                align="center">
          <template slot-scope="scope">
            {{scope.row.driverExpress}}
          </template>
        </el-table-column>

        <el-table-column
          label="运费收款人"
          width="100"
          align="center">
          <template slot-scope="scope">
            {{scope.row.payeeUserName}}
          </template>
        </el-table-column>

        <el-table-column
          label="是否有票据"
          width="100"
          align="center">
          <template slot-scope="scope">
            {{scope.row.isHasBill  == 1 ? '有票据' : '无票据'}}
          </template>
        </el-table-column>

        <el-table-column
                align="center"
                label="费用类型"
                width="100">
          <template slot-scope="scope">
            {{scope.row.freightType}}
          </template>
        </el-table-column>
        <el-table-column
                label="物流毛利"
                width="100"
                align="center">
          <template slot-scope="scope">
            {{scope.row.logisticsProfit}}
          </template>
        </el-table-column>
        <el-table-column
                label-class-name="bgth"
                :render-header="renderHeader"
                width="100"
                align="center">
          <template slot-scope="scope">
            {{scope.row.costPrice}}
          </template>
        </el-table-column>
        <el-table-column
          label="退税金额"
          width="100"
          align="center">
          <template slot-scope="scope">
            {{scope.row.returnTaxAmount}}
          </template>
        </el-table-column>
        <el-table-column
                :render-header="renderHeader4"
                width="100"
                align="center">
          <template slot-scope="scope">
            {{scope.row.goodsCashPrice}}
          </template>
        </el-table-column>

        <el-table-column
                :render-header="renderHeader2"
                width="100"
                align="center">
          <template slot-scope="scope">
            {{scope.row.costCashPrice}}
          </template>
        </el-table-column>
        <el-table-column
          label="采购订单号"
          width="100"
          align="center">
          <template slot-scope="scope">
              {{scope.row.purchaseOrderSn}}
          </template>
        </el-table-column>
          <el-table-column
                  label="采购源单号"
                  width="100"
                  align="center">
              <template slot-scope="scope">
                <el-link @click="toinWarehouseDetail(scope.row.purchaseEntrySn)" type="primary" style="font-size:12px">
                  {{scope.row.purchaseEntrySn}}
                </el-link>
              </template>
          </el-table-column>
        <el-table-column
          label="采购合同公司"
          width="100"
          align="center">
          <template slot-scope="scope">
              {{scope.row.entryFromCompany }}
          </template>
        </el-table-column>
        <el-table-column
                label="货源介绍人"
                width="100"
                align="center">
          <template slot-scope="scope">
            {{scope.row.purchaseUserName}}
          </template>
        </el-table-column>
        <el-table-column
          label="采购员"
          width="100"
          align="center">
          <template slot-scope="scope">
            {{scope.row.purchaseSalesMan}}
          </template>
        </el-table-column>
        <el-table-column
                label="销售采购毛利"
                width="100"
                align="center">
          <template slot-scope="scope">
            {{scope.row.salePurchaseProfit}}
          </template>
        </el-table-column>
        <el-table-column
                label="采购预估底价"
                width="120"
                align="center">
          <template slot-scope="scope">
            {{scope.row.purchasePrice}}
          </template>
        </el-table-column>
        <el-table-column
                label-class-name="bgth"
                label="采购实际底价"
                width="140"
                align="center">
          <template slot-scope="scope">
            {{scope.row.purchaseActualPrice}}
          </template>
        </el-table-column>
        <el-table-column
                :render-header="renderHeader3"
                width="100"
                align="center">
          <template slot-scope="scope">
            {{scope.row.purchaseCashPrice}}
          </template>
        </el-table-column>
        <el-table-column
                label-class-name="bgth"
                label="销售发货现金价毛利"
                width="140"
                align="center">
          <template slot-scope="scope">
            {{scope.row.saleProfit}}
          </template>
        </el-table-column>
<!--        <el-table-column-->
<!--                label-class-name="bgth"-->
<!--                label="销售发货加成现金价毛利"-->
<!--                width="140"-->
<!--                align="center">-->
<!--          <template slot-scope="scope">-->
<!--            {{scope.row.saleProfitEnd}}-->
<!--          </template>-->
<!--        </el-table-column>-->

        <el-table-column
                label-class-name="bgth"
                label="推荐佣金"
                width="120"
                align="center">
          <template slot-scope="scope">
            {{scope.row.saleCommissionProfit}}
          </template>
        </el-table-column>
        <el-table-column
                label-class-name="bgth"
                label="销售实际发货现金毛利"
                width="100"
                align="center">
          <template slot-scope="scope">
            {{scope.row.saleActualProfit}}
          </template>
        </el-table-column>
        <el-table-column
                label-class-name="bgth"
                label="销售发货毛利"
                width="100"
                align="center">
          <template slot-scope="scope">
            {{scope.row.saleSendProfit}}
          </template>
        </el-table-column>
        <el-table-column
                label-class-name="bgth"
                label="金蝶毛利"
                width="100"
                align="center">
          <template slot-scope="scope">
            {{scope.row.kingProfit}}
          </template>
        </el-table-column>
        <el-table-column
                label-class-name="bgth"
                label="结算毛利"
                width="100"
                align="center">
          <template slot-scope="scope">
            {{scope.row.settleProfit}}
          </template>
        </el-table-column>
        <el-table-column
          label-class-name="bgth"
          label="系统毛利"
          width="100"
          align="center">
          <template slot-scope="scope">
            {{scope.row.systemProfit}}
          </template>
        </el-table-column>

        <el-table-column
          label="牌号系数"
          width="100"
          prop="profitRate"
          align="center">
        </el-table-column>

        <el-table-column
                label="预计发货仓库"
                width="120"
                align="center">
          <template slot-scope="scope">
            {{scope.row.warehouseName}}
          </template>
        </el-table-column>
        <el-table-column
                label="实际发货仓库"
                width="120"
                align="center">
          <template slot-scope="scope">
            {{scope.row.shipWarehouse}}
          </template>
        </el-table-column>
        <el-table-column
                label="期望发货日期"
                width="120"
                align="center">
          <template slot-scope="scope">
            {{scope.row.expectSendDate}}
          </template>
        </el-table-column>
        <el-table-column
                label="预计发货日期"
                width="120"
                align="center">
          <template slot-scope="scope">
            {{scope.row.sendDate}}
          </template>
        </el-table-column>
        <el-table-column
                align="center"
                label="实际发货日期"
                width="120">
          <template slot-scope="scope">
            {{scope.row.shipDate}}
          </template>
        </el-table-column>
        <el-table-column
                label="推荐类型"
                width="100"
                align="center">
          <template slot-scope="scope">
            {{scope.row.introducerType | fifIntroducerType }}
          </template>
        </el-table-column>
        <el-table-column
                label="推荐人"
                width="100"
                align="center">
          <template slot-scope="scope">
            {{scope.row.introducerName }}
          </template>
        </el-table-column>

        <el-table-column
          label="是否需要复核"
          width="150"
          align="center">
          <template slot-scope="scope">
            {{scope.row.isNeedRecheck | fifisNeedRecheck }}
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination-container">
      <el-pagination
              background
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              layout="total, sizes,prev, pager, next,jumper"
              :current-page.sync="listQuery.pageNum"
              :page-size="listQuery.pageSize"
              :page-sizes="[10,15,20]"
              :total="count">
      </el-pagination>
    </div>

  </div>
</template>
<script>
import {
  getCustomerOption,
  getOrderUsersList,
  getProfitRateListAPI,
  getDeliverDetailList,
  exportDeliverDetailList,
  getShipWarehouseList,
  supplierList,
  getConfigList
} from '@/api/partner'
  import {formatDate} from '@/utils/date';
  import store from '@/store'
  import { mapGetters } from 'vuex'
  const defaultListQuery={
    pageNum: 1,
    pageSize: 10,
    goodsName: '',
    createDate:null,
    deliverDate:null,
    customerName:null,
    deliverSn:'',
    userId: [],
    profitRate:[],
    isYunlianDeliver:'',
    orderSn:'',
    purchaseUserId:'',
    goodsSn:'',
    freightType:'',
    fromCompany:'',
    customerLabel:'',
    kingGoodsIds:[],
    introducerType:null,
    introducerName:null,
    purchaseEntrySn:'',
    shipWarehouse:[],
    isMoresuOnlineOrder:'',
    isChina:'',
    freightTime:[],
    isFilterOrder:'',
    payState:[],
    isNewCustomer:0,
    supplierId:'',
    isAgreement: '',
    isOrderClose:'',
    orderCustomerType:''
  };
  export default {
    name: "index",
    data(){
      return {
        listQuery: JSON.parse(JSON.stringify(defaultListQuery)),
        tableData: [],
        count: 0,
        listLoading: false,
        roles:store.getters.roles ? store.getters.roles : [],
        userOptionList: [],
        profitRateList:[],
        sendAllNum:'',
        allProfit:'',
        settleProfit:'',
        // goodsList:[],
        downloadLoading:false,
        shipWarehouseList:[],
        actualFreight:'',
        purchaseProfit:'',
        saleProfit:'',
        options2:[],
        orderCustomerTypeList:[]
      }
    },
    computed: {
      ...mapGetters([
        'name',
        'mobile',
        'userId'
      ]),

      isCanSaleByDept(){
        if(this.roles.indexOf("saleDept") != -1){
          return true
        }else{
          return false
        }
      },
      isCanSaleByAll(){
        if(this.roles.indexOf("saleAll") != -1){
          return true
        }else{
          return false
        }
      },
      deliverDetailsReportExport(){
        if(this.roles.indexOf("deliverDetailsReportExport") != -1){
          return true
        }else{
          return false
        }
      },
    },
    created() {
      let now = new Date();
      let nowMonth = now.getMonth(); //当前月
      let nowYear = now.getFullYear(); //当前年
      //本月的开始时间
      let monthStartDate = new Date(nowYear, nowMonth, 1);
      //本月的结束时间
      let monthEndDate = new Date(nowYear, nowMonth+1, 0,23,59,59);
      let startDate = formatDate(monthStartDate, 'yyyy-MM-dd hh:mm:ss');
      let endDate = formatDate(monthEndDate, 'yyyy-MM-dd hh:mm:ss');
      this.listQuery.deliverDate = [startDate,endDate];
      if(this.$route.query.type){
        switch (this.$route.query.type) {
          case 'my':
            this.listQuery.tab = 'my';
            break;
          case 'myDay':
            this.listQuery.tab = 'my';
            this.listQuery.createdAt = [formatDate(new Date(), 'yyyy-MM-dd'),formatDate(new Date(), 'yyyy-MM-dd')];
            break;
          case 'dept':
            this.listQuery.tab = 'dept';
            break;
          case 'deptDay':
            this.listQuery.tab = 'dept';
            this.listQuery.createdAt = [formatDate(new Date(), 'yyyy-MM-dd'),formatDate(new Date(), 'yyyy-MM-dd')];
            break;
          case 'company':
            this.listQuery.tab = 'company';
            break;
          case 'companyDay':
            this.listQuery.tab = 'company';
            this.listQuery.createdAt = [formatDate(new Date(), 'yyyy-MM-dd'),formatDate(new Date(), 'yyyy-MM-dd')];
            break;
        }
      }
      this.getList();
      this.getShipWarehouseData();
      this.getUserOptionList();
      this.getProfitRateList()
      this.getSupplierList()
      this.getOrderCustomerType()
      // this.getOrderGoodsList();
    },
    filters: {
      fifisNeedRecheck(val){
        if(val == 0){
          return '未申请'
        }else if(val == 1){
          return '待复核'
        }else if(val == 2){
          return '已复核'
        }
      },
      filterIsChina(val){
          if(val== 2){
            return '外贸'
          } else if(val == 1){
            return '内销'
          }
        },
      formatCreateTime(time) {
        if(time){
          let date = new Date(time);
          return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
        }else{
          return '--'
        }
      },
      fifIntroducerType(val){
        if(val == 1){
          return '外部人员'
        }else if(val == 2){
          return '内部人员'
        }
      },
    },
    methods:{
      //获取订单分类列表
      getOrderCustomerType(){
        getConfigList({status:1}).then((res)=>{
          let orderCustomerType = res.find((el)=>{
            return  el.cdtCode == 'order_customer_type'
          })
          this.orderCustomerTypeList = orderCustomerType ? orderCustomerType.data : []
        })
      },
      //供应商
      getSupplierList() {
        supplierList().then((res)=>{
          this.options2 = res;
        })
      },
      getShipWarehouseData(){
        getShipWarehouseList().then((res)=>{
          this.shipWarehouseList = res;
        })
      },
      // getOrderGoodsList(){
      //   orderGoodsList().then((res)=>{
      //       this.goodsList = res.list
      //   })
      // },
      //下载excle
      downloadExcel(){
        let params = JSON.parse(JSON.stringify(this.listQuery));
        params.type = 'finance';
        this.downloadLoading = true;
        exportDeliverDetailList(params).then((res)=>{
          this.downloadLoading = false;
          require.ensure([], () => {
            const { export_json_to_excel } = require('sheet/Export2Excel');
            const tHeader = res.title;
            const filterVal = res.columns;
            const list = res.list;
            const data = this.formatJson(filterVal, list);
            export_json_to_excel(tHeader, data, res.fileName);
          })
        }).catch(()=>{
          this.downloadLoading = false;
        })
      },

      //下载表格数据格式化
      formatJson(filterVal, jsonData) {
        return jsonData.map(v => filterVal.map(j => v[j]))
      },
      //查看发货单
      toDeliverDetail(deliverId){
        let routeData = this.$router.resolve({name:'deliverCon',query:{id:deliverId,type:'caiWu',}});
        window.open(routeData.href);
      },

      //查看入库单
      toinWarehouseDetail(purchaseEntrySn){
        let routeData = this.$router.resolve({name:'inWarehouseDetail',query:{id:purchaseEntrySn}});
        window.open(routeData.href);
      },

      toOrderDetail(orderId){
        let routeData = this.$router.resolve({name:'purchaseDetail',query:{id:orderId,type:'see'}});
        window.open(routeData.href);
      },

      renderHeader (h) {
        return [h('div', {}, ['金蝶']),h('div', {}, ['成本单价'])]
      },

      renderHeader2 (h) {
        return [h('div', {}, ['成本单价']),h('div', {}, ['现金价'])]
      },
      renderHeader3 (h) {
        return [h('div', {}, ['采购底价']),h('div', {}, ['现金价'])]
      },
      renderHeader4 (h) {
        return [h('div', {}, ['合同单价']),h('div', {}, ['现金价'])]
      },

      //获取员工下拉选项
      getUserOptionList(){
        getOrderUsersList().then((res)=>{
          this.userOptionList = res;
        })
      },

      //获取牌号系数列表
      getProfitRateList(){
        getProfitRateListAPI().then((res)=>{
          console.log('res',res);
          this.profitRateList = res;
        })
      },


      //选择员工名称
      handleSelectUserName(key,item){
        this.listQuery[key] = item.userId;
      },


      //客户名称输入匹配
      querySearch(queryString, cb){
        getCustomerOption({keywords:queryString}).then((res)=>{
          cb(res);
        })
      },


      //选择客户名称
      handleSelectCustomerName(item){
        this.listQuery.keywords = item.customerName
      },

      /**
       * 切换选择状态
       */
      handleSelect(key, keyPath){
        this.listQuery = JSON.parse(JSON.stringify(defaultListQuery)),
                this.listQuery.tab = key;
        this.handleSearchList();
      },
      handleSizeChange(val){
        this.listQuery.pageNum = 1;
        this.listQuery.pageSize = val;
        this.getList();
      },
      handleCurrentChange(val){
        this.listQuery.pageNum = val;
        this.getList();
      },

      handleSearchList(){
        this.listQuery.pageNum = 1;
        this.getList();
      },

      //获取发货明细列表
      getList() {
        this.listLoading = true;
        getDeliverDetailList(this.listQuery).then(response => {
          this.tableData = response.list;
          this.count = response.count;
          this.sendAllNum = response.sendAllNum;
          this.allProfit = response.allProfit;
          this.actualFreight = response.actualFreight
          this.purchaseProfit = response.purchaseProfit
          this.saleProfit = response.saleProfit
          // this.settleProfit = response.settleProfit;
          this.listLoading = false;
        }).catch(()=>{
          this.listLoading = false;
        });
      },

    },
  }
</script>

<style scoped lang="scss">

  .upload-div{
    text-align: center;
    position:relative;
    #upload{

      opacity: 0;
      position: absolute;
      z-index: 1;
      width:154px;
      height:40px
    }
  }
</style>
